import { Router } from "vue-router";

export function throttle(
  timeout: number,
  fn: (...args: any) => Promise<unknown>
) {
  return _.throttle(fn, timeout, { leading: true, trailing: false });
}

export const throttle1sec = _.curry(throttle)(1000);
export const throttle2sec = _.curry(throttle)(2000);
export const throttle3sec = _.curry(throttle)(3000);
export const updateThrottle = <T> (fn: (...args: any) => Promise<T>) =>
  _.throttle(fn, 1000, { leading: false, trailing: true });

export function debugLog(...args: any): void {
  if (import.meta.env.DEV) {
    console.log("[debug]", ...args);
  }
}


export const getChildrenRoutes = (router: Router, parentPath: string) => {
  const rs = router.getRoutes()
  return rs.filter(route => route.path.startsWith(parentPath) && !route.path.startsWith('/:') && route.path !== parentPath)
}

